package cn.gz.demo;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import androidx.multidex.MultiDex;

import cn.gz.demo.dao.DaoMaster;
import cn.gz.demo.dao.DaoSession;
import cn.gz.demo.utils.BaseContext;

/**
 * Created by Liuyz on 2017/8/29.
 */
public class BaseApplication extends Application {
    public static boolean isShow = true; // 日志开关
    public static final int time = 800; // 控件点击间距时间
    public static BaseApplication instances;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        BaseContext.init(this); // 初始化上下文
        instances = this;

        //初始化数据库
        initDB();
    }

    private DaoMaster.DevOpenHelper mHelper;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    private SQLiteDatabase db;

    private void initDB() {
        mHelper = new DaoMaster.DevOpenHelper(this, "demo.db", null);
        db = mHelper.getWritableDatabase();
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }

    public static BaseApplication getInstances() {
        return instances;
    }

    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public SQLiteDatabase getDb() {
        return db;
    }

}
